@echo off
set user=zhangyu
set host=172.21.227.206
set rootDir=/home/zhangyu/Program/wgr_daily
set exeSrcDir=%rootDir%/code/out/ohos-arm-release/mingw_x86_64/common/common
set exeDstDir=D:\WorkDir\temp\previewer
set exeLists=ace_test_windows_phone;ace_test_windows_tv;ace_test_windows_car;ace_test_windows_tablet

@REM 编译wagner主干镜像
set initCode=repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify
set syncCode=repo sync -c
set pulllfs=repo forall -c 'git lfs pull'
set prebuiltCode=bash build/prebuilts_download.sh
set buildCode=./build.sh --product-name ohos-sdk --gn-args use_musl=false --gn-args use_custom_libcxx=true --gn-args use_custom_clang=true --gn-args enable_glfw_window=true --build-target ace_for_windows
set testLog=D:\WorkDir\temp\test.log
set runLog=D:\WorkDir\temp\run.log

echo "rm -rf %rootDir%" > %testLog%
ssh %user%@%host% "rm -rf %rootDir%" > %runLog%

echo "mkdir -p %rootDir%/code" >> %testLog%
ssh %user%@%host% "mkdir -p %rootDir%/code" >> %runLog%

echo %initCode% >> %testLog%
ssh %user%@%host% "cd %rootDir%/code; %initCode%" >> %runLog%

echo %syncCode% >> %testLog%
ssh %user%@%host% "cd %rootDir%/code; %syncCode%" >> %runLog%

echo %pulllfs% >> %testLog%
ssh %user%@%host% "cd %rootDir%/code; %pulllfs%" >> %runLog%

echo %prebuiltCode% >> %testLog%
ssh %user%@%host% "cd %rootDir%/code; %prebuiltCode%" >> %runLog%

echo %buildCode% >> %testLog%
ssh %user%@%host% "cd %rootDir%/code; %buildCode%" >> %runLog%


if exist %exeDstDir% (
    rmdir /q/s %exeDstDir%
)
set ftpFile=sftp.txt
>%ftpFile% (
    echo get -r %exeSrcDir% %exeDstDir%
    echo bye
)
sftp -b %ftpFile% %user%@%host%
del %ftpFile%

@REM 执行预览测试
cd %exeDstDir%
for %%i in (%exeLists%) do (
    if not exist %%i.exe(
        echo %%i.exe not exist.
    ) else {
        @REM 测试1.0
        start "" "%%i.exe" ""
        timeout /T 10
        taskkill /im %%i.exe /f
        fc InspectorTree.txt ..\correct\%%i.txt && echo test %%i.exe successful >> %testLog% || echo test %%i.exe failed >> %testLog%

        @REM 测试2.0
        start "" "%%i.exe" "2.0"
        timeout /T 10
        taskkill /im %%i.exe /f
        fc InspectorTree.txt ..\correct\%%i_2.txt && echo test %%i.exe 2.0 successful >> %testLog% || echo test %%i.exe 2.0 failed >> %testLog%
    }
)